var pageNum=1;//当前页
var pageSize=10;//页容量
var total=0;//总条数
var pages=0;//总页数


function showInfo() {
    let positionName=$("#positionName").val()
    let positionSort=$("#positionSort option:selected").val()
    let registranTime=$("#registranTime").val()
    let expirationDate=$("#expirationDate").val()

    let jsonA={
        'positionName':positionName,
        'positionSort':positionSort,
        'registranTime':registranTime,
        'expirationDate':expirationDate,
        'pageNum':pageNum,
        'pageSize':pageSize
    }

    $.ajaxSettings.async = false;
    $.get('show',jsonA,function (dataA) {
        let title="<tr><th>招聘信息编号</th><th>职位编码</th><th>职位名称</th><th>职位分类</th><th>所属部门</th><th>招聘人数</th><th>登记日期</th><th>截止日期</th><th>操作</th></tr>";
        $("#positionData").html('').append(title)
        var da=dataA.list
        $(da).each(function () {

            var str="<tr>\n" +
                "<td>"+this.employmentId+"</td>                " +
                "<td>"+this.positionId+"</td>\n" +
                " <td>"+this.positionName+"</td>\n" +
                " <td>"+this.positionSort+"</td>\n" +
                " <td>"+this.department+"</td>\n" +
                " <td>"+this.numbers+"</td>\n" +
                " <td>"+this.registranTime+"</td>\n" +
                " <td>"+this.expirationDate+"</td>\n" +
                " <td><button type='button' class='layui-btn layui-btn-sm' onclick='goUpInfo(this.id,this.name,this.value)' id='"+this.employmentId+"' name='"+this.positionId+"' value='"+this.department+"'>变更</button>&nbsp;&nbsp;<button type='button' class='layui-btn layui-btn-sm' onclick='look(this.name)' name='"+this.employmentId+"'>明细</button>&nbsp;&nbsp;<button type='button' class='layui-btn layui-btn-sm' onclick='del(this.name,this)' name='"+this.employmentId+"'>删除</button></td>\n" +
                "   </tr>"
            $("#positionData").append(str)
        })
        pages=dataA.pages;
    },'json')
    $.ajaxSettings.async = true;
    showPage()
}
//展示页码
function showPage() {
    $(".showPage").text(pageNum + " / " + pages );
}


// 上一页
function prv() {
    pageNum--;
    if (pageNum < 1) {
        pageNum = 1;
        return;
    }
    showInfo();

}
// 首页
function first() {
    pageNum = 1
    showInfo();
}
// 尾页
function last() {
    pageNum = pages;
    showInfo();
}


function next(){
    pageNum++;
    if (pageNum > pages) {
        pageNum = pages;
        return;
    }
    showInfo();
}

function goPosition() {
    location.href="/getDepartment"
}

function goUpInfo(thisA,thisB,thisC){
    location.href="/goUpInfo?employmentId="+thisA+"&positionId="+thisB+"&allName="+thisC
}

function look(thisA) {
    location.href="/look?employmentId="+thisA
}

function del(thisA,thisB) {
    let bo=confirm("招聘信息删除后将无法恢复，确定删除吗？")
    if (!bo){
        return;
    }
    if (bo){
        let json={
            employmentId:thisA
        }


        $.ajaxSettings.async=false
        $.get("del",json,function (dataA) {
            if (dataA>0){
                $(thisB).parents("tr").remove();
                layer.msg("删除成功！")
            }else {
                layer.msg("删除失败！")
            }
        })
        $.ajaxSettings.async=true
    }
}